package b3.widget.mail
{
	import b3.config.*;
	import b3.model.Obj;
	import b3.net.ResourceHelper;
	import b3.util.*;
	import b3.widget.*;
	import b3.widget.basic.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;

	public class ObjNumSelectDialog extends BasicWidget
	{
		private var objectIndex:int;
		private var numSel:NumberSelecter;
		private var objectSprite:Sprite;
		private var buttonClose:BasicButton;
		private var buttonOK:BasicButton;
		
		public function ObjNumSelectDialog(objectIndex:int)
		{
			super();
			this.objectIndex = objectIndex;
			this.anchor = BasicWidget.ANCHOR_MIDDLE_MIDDLE;
			var DialogBgr:Class = ResourceHelper.getInstance().getClassByName("MessageBoxBgr2");
			addChild(new DialogBgr());
			//标题
			var titleField:TextField = new TextField();
			titleField.selectable = false;
        	titleField.autoSize = TextFieldAutoSize.CENTER;
			titleField.defaultTextFormat = new TextFormat(BFont.fontName, 20, 0xFFFFFF, true);
			titleField.filters = [new GlowFilter(0x00AAFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			titleField.x = this.width / 2;
			titleField.y = 20;
			titleField.text = "请选择物品数量！";
			addChild(titleField);
			//图标
			var objectConfig:ObjConfig = Config.objConfigs[objectIndex];
			var ObjectImage:Class = ResourceHelper.getInstance().getClassByName(objectConfig.iconImage[0]);
			objectSprite = new ObjectImage();
			objectSprite.x = 80;
			objectSprite.y = 80;
			addChild(objectSprite);
			//数量选择
			var ButtonBgr:Class = ResourceHelper.getInstance().getClassByName("ButtonBgr0");
			var LeftArrow:Class = ResourceHelper.getInstance().getClassByName("TabPagePageUp");
			var RightArrow:Class = ResourceHelper.getInstance().getClassByName("TabPagePageDown");
			numSel = new NumberSelecter(LeftArrow, RightArrow);
			numSel.x = 180;
			numSel.y = 100;
			addChild(numSel);
			//关闭
			buttonClose = new BasicButton(ButtonBgr, "取消");
			buttonClose.x = 180;
			buttonClose.y = 160;
			buttonClose.addEventListener(MouseEvent.CLICK, onCloseClick);
			addChild(buttonClose);
			//确定
			buttonOK = new BasicButton(ButtonBgr, "确定");
			buttonOK.x = 80;
			buttonOK.y = 160;
			buttonOK.addEventListener(MouseEvent.CLICK, onButtonOKMouseClick);
			addChild(buttonOK);
			this.x = -this.width / 2;
			this.y = -this.height / 2;
		}
		
		public function onCloseClick(event:MouseEvent):void
		{
			close();
		}
		
		public function onButtonOKMouseClick(event:MouseEvent):void
		{
			var obj:Obj = new Obj();
			obj.objectIndex = objectIndex;
			obj.objectNum = numSel.value;
			var mailDialog:MailDailog = WidgetManager.getInstance().getWidget(MailDailog) as MailDailog;
			mailDialog.addOjbect(obj);
			close();
		}
	}
}